package com.wjh.yygh.user.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wjh.cmn.client.DictFeignClient;
import com.wjh.yygh.enums.DictEnum;
import com.wjh.yygh.model.user.Patient;
import com.wjh.yygh.user.service.PatientService;
import com.wjh.yygh.user.mapper.PatientMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author wangjunhong
* @description 针对表【patient(就诊人表)】的数据库操作Service实现
* @createDate 2022-08-11 23:14:28
*/
@Service
public class PatientServiceImpl extends ServiceImpl<PatientMapper, Patient>
    implements PatientService{

    @Autowired
    private DictFeignClient dictFeignClient;

    @Override
    public List<Patient> findAllByUserId(Long userId) {
        QueryWrapper<Patient> patientQueryWrapper = new QueryWrapper<>();
        patientQueryWrapper.eq("user_id",userId);
        List<Patient> patients = baseMapper.selectList(patientQueryWrapper);
        patients.stream().forEach(patient -> {
            this.packPainent(patient);
        });
        return patients;
    }

    @Override
    public Patient getPatientById(Long id) {
        Patient patient = baseMapper.selectById(id);
        this.packPainent(patient);
        return patient;
    }


    private void packPainent(Patient patient) {
        //证件类型， 根据证件类型和证件编码查询
        String certificatesTypeName = dictFeignClient.getName(DictEnum.CERTIFICATES_TYPE.getDictCode(), patient.getCertificatesType());
//        联系人的证件类型
        String contactscertificatesTypeName = dictFeignClient.getName(DictEnum.CERTIFICATES_TYPE.getDictCode(), patient.getCertificatesType());
        //所在省
        String  provinceName= dictFeignClient.getName(patient.getProvinceCode());
        //所在市
        String cityName = dictFeignClient.getName(patient.getCityCode());
        //所在区
        String districtName = dictFeignClient.getName(patient.getDistrictCode());

        patient.getParam().put("certificatesTypeString",certificatesTypeName);
        patient.getParam().put("contactscertificatesTypeString",contactscertificatesTypeName);
        patient.getParam().put("provinceString",provinceName);
        patient.getParam().put("cityString",cityName);
        patient.getParam().put("districtString",districtName);
        patient.getParam().put("fullAddress",provinceName+cityName+districtName);
    }
}




